package cn.bupt.adt.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.bupt.adt.controller.inf.AliPayController;
import cn.bupt.adt.dao.autogenerate.RechargeMapper;
import cn.bupt.adt.entity.autogenerate.Recharge;
import cn.bupt.adt.service.IRechargeService;
@Service
public class RechargeService implements IRechargeService {

	@Autowired 
	RechargeMapper rechargeMapper;
	@Override
	public boolean addRecharge(Recharge recharge) {
		int i = rechargeMapper.insert(recharge);
		return i == 1;
	}
	@Override
	public Recharge getRechargeById(int rechargeId) {
		
		return rechargeMapper.selectByPrimaryKey(rechargeId);
	}
	@Override
	public boolean updateRechargeByPrimaryKeySelective(Recharge recharge) {
		return rechargeMapper.updateByPrimaryKeySelective(recharge) == 1;
	}
	@Override
	public boolean verifyRecharge(int rechargeId, String verifyCode) {
		Recharge recharge = rechargeMapper.selectByPrimaryKey(rechargeId);
		if(recharge == null)
			AliPayController.alipayLogger.info("recharge is null");
		else {
			AliPayController.alipayLogger.info("校验码相等否："+recharge.getVerifyCode().equals(verifyCode));
		}
		return recharge == null ? false:recharge.getVerifyCode().equals(verifyCode);
	}

}
